home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / float / dpa_atan2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-09  |  670 b   |  31 lines

  1.  
  2. /*
  3.  *  FLOAT/DPA_ATAN2.C    Courtesy of Klaxon Suralis
  4.  *
  5.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  6.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  7.  *    DICE-LICENSE.TXT.
  8.  *
  9.  */
  10.  
  11. #include <math.h>
  12.  
  13. double
  14. atan2(double y, double x)
  15. {
  16.     double pi =       3.14159265358979323 ;    /* from memory         */
  17.     double piover2  = 3.14159265358979323/2.0 ; /* / at compile time?*/
  18.     double temp ;
  19.  
  20.     if (x==0.0) {
  21.     return ((y >= 0.0) ? piover2 : -piover2);
  22.     } else {
  23.     temp = atan(y/x);
  24.     if  (x > 0.0)
  25.         return (temp);    /* this is the easy way out  */
  26.     else
  27.         return ((temp >= 0.0) ? (temp-pi) : (temp+pi));
  28.     }
  29. }
  30.  
  31.